/**
 * Copyright &copy; 2012-2014 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package cn.apestar.modules.meibang.consultation.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import cn.apestar.common.config.Global;
import cn.apestar.common.persistence.Page;
import cn.apestar.common.utils.StringUtils;
import cn.apestar.common.web.BaseController;
import cn.apestar.modules.meibang.consultation.entity.BeautyConsultationOrderAnswer;
import cn.apestar.modules.meibang.consultation.service.BeautyConsultationOrderAnswerService;

/**
 * answerController
 * @author answer
 * @version 2017-06-05
 */
@Controller
@RequestMapping(value = "${adminPath}/consultation/answer")
public class BeautyConsultationOrderAnswerController extends BaseController {

    @Autowired
    private BeautyConsultationOrderAnswerService beautyConsultationOrderAnswerService;

    @ModelAttribute
    public BeautyConsultationOrderAnswer get(@RequestParam(required = false) String id) {
        BeautyConsultationOrderAnswer entity = null;
        if (StringUtils.isNotBlank(id)) {
            entity = beautyConsultationOrderAnswerService.get(id);
        }
        if (entity == null) {
            entity = new BeautyConsultationOrderAnswer();
        }
        return entity;
    }

    @RequestMapping(value = {"list" , ""})
    public String list(BeautyConsultationOrderAnswer beautyConsultationOrderAnswer, HttpServletRequest request, HttpServletResponse response,
        Model model) {
        Page<BeautyConsultationOrderAnswer> page = beautyConsultationOrderAnswerService.findPage(new Page<BeautyConsultationOrderAnswer>(request,
            response), beautyConsultationOrderAnswer);
        model.addAttribute("page", page);
        return "modules/meibang/consultation/beautyConsultationOrderAnswerList";
    }

    @RequestMapping(value = "form")
    public String form(BeautyConsultationOrderAnswer beautyConsultationOrderAnswer, Model model) {
        model.addAttribute("beautyConsultationOrderAnswer", beautyConsultationOrderAnswer);
        return "modules/meibang/consultation/beautyConsultationOrderAnswerForm";

    }

    @RequestMapping(value = "modifyForm")
    public String modifyForm(BeautyConsultationOrderAnswer beautyConsultationOrderAnswer, Model model) {
        model.addAttribute("beautyConsultationOrderAnswer", beautyConsultationOrderAnswer);
        return "modules/meibang/consultation/beautyConsultationAnswerModifyForm";

    }

    @RequestMapping(value = "save")
    public String save(BeautyConsultationOrderAnswer beautyConsultationOrderAnswer, Model model, RedirectAttributes redirectAttributes) {
        if (!beanValidator(model, beautyConsultationOrderAnswer)) {
            return form(beautyConsultationOrderAnswer, model);
        }
        beautyConsultationOrderAnswerService.save(beautyConsultationOrderAnswer);
        addMessage(redirectAttributes, "保存成功");
        return "redirect:" + Global.getAdminPath() + "/consultation?repage";
    }

    @RequestMapping(value = "delete")
    public String delete(BeautyConsultationOrderAnswer beautyConsultationOrderAnswer, RedirectAttributes redirectAttributes) {
        beautyConsultationOrderAnswerService.delete(beautyConsultationOrderAnswer);
        addMessage(redirectAttributes, "删除成功");
        return "redirect:" + Global.getAdminPath() + "/consultation/answer?repage";
    }

}